#include <vector>
#include <exception>

#include <glpk.h>

#include "variable.hh"
#include "constraint.hh"
#include "objective_function.hh"
#include <iostream>

class VariableUndefined : public std::exception
{
public:
  VariableUndefined(const std::string& var_name);

  virtual const char* what() const throw();

  virtual ~VariableUndefined() throw() {};

private:
  std::string var_name;
};

class problem
{
public:

  problem(const std::string& name);

  ~problem();

  void run();

  void add(variable v);

  void add(constraint c);

  void add(objective_function f);

  friend std::ostream& operator<< (std::ostream&, const problem& w);

  double to_result(const variable& v) const;

  void display_result() const;

  const variable& var(const std::string& name) const;

protected:

  objective_function f;

  std::vector<variable> variables;

  std::vector<constraint> constraints;

  glp_prob* lp;

  std::string name;
};
